home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / Zend / zend_fast_cache.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-18  |  4.0 KB  |  141 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_FAST_CACHE_H
  22. #define ZEND_FAST_CACHE_H
  23.  
  24. #ifndef ZEND_ENABLE_FAST_CACHE
  25. # if ZEND_DEBUG
  26. # define ZEND_ENABLE_FAST_CACHE 0
  27. # else
  28. # define ZEND_ENABLE_FAST_CACHE 1
  29. # endif
  30. #endif
  31.  
  32. typedef struct _zend_fast_cache_list_entry {
  33.     struct _zend_fast_cache_list_entry *next;
  34. } zend_fast_cache_list_entry;
  35.  
  36. #define MAX_FAST_CACHE_TYPES    4
  37.  
  38.  
  39. #define ZVAL_CACHE_LIST            0
  40. #define HASHTABLE_CACHE_LIST    1
  41.  
  42. #if ZEND_ENABLE_FAST_CACHE
  43.  
  44.  
  45. #include "zend_globals.h"
  46. #include "zend_globals_macros.h"
  47. #include "zend_alloc.h"
  48.  
  49.  
  50. #if ZEND_DEBUG
  51. # define RECORD_ZVAL_CACHE_HIT(fc_type)        AG(fast_cache_stats)[fc_type][1]++;
  52. # define RECORD_ZVAL_CACHE_MISS(fc_type)    AG(fast_cache_stats)[fc_type][0]++;
  53. #else
  54. # define RECORD_ZVAL_CACHE_HIT(fc_type)
  55. # define RECORD_ZVAL_CACHE_MISS(fc_type)
  56. #endif
  57.  
  58.  
  59. #define ZEND_FAST_ALLOC(p, type, fc_type)                                \
  60.     {                                                                \
  61.         ALS_FETCH();                                                \
  62.                                                                     \
  63.         if (((p) = (type *) AG(fast_cache_list_head)[fc_type])) {    \
  64.             AG(fast_cache_list_head)[fc_type] = ((zend_fast_cache_list_entry *) AG(fast_cache_list_head)[fc_type])->next;    \
  65.             RECORD_ZVAL_CACHE_HIT(fc_type);                            \
  66.         } else {                                                    \
  67.             (p) = (type *) emalloc(sizeof(type));                    \
  68.             RECORD_ZVAL_CACHE_MISS(fc_type);                        \
  69.         }                                                            \
  70.     }
  71.  
  72.  
  73. #define ZEND_FAST_FREE(p, fc_type)                                        \
  74.     {                                                                \
  75.         ALS_FETCH();                                                \
  76.                                                                     \
  77.         ((zend_fast_cache_list_entry *) (p))->next = (zend_fast_cache_list_entry *) AG(fast_cache_list_head)[fc_type];    \
  78.         AG(fast_cache_list_head)[fc_type] = (zend_fast_cache_list_entry *) (p);            \
  79.     }
  80.  
  81. #define ZEND_FAST_ALLOC_REL(p, type, fc_type)    \
  82.     ZEND_FAST_ALLOC(p, type, fc_type)
  83.  
  84. #define ZEND_FAST_FREE_REL(p, fc_type)    \
  85.     ZEND_FAST_FREE(p, fc_type)
  86.  
  87.  
  88. #else /* !ZEND_ENABLE_FAST_CACHE */
  89.  
  90. #define ZEND_FAST_ALLOC(p, type, fc_type)    \
  91.     (p) = (type *) emalloc(sizeof(type))
  92.  
  93. #define ZEND_FAST_FREE(p, fc_type)    \
  94.     efree(p)
  95.  
  96. #define ZEND_FAST_ALLOC_REL(p, type, fc_type)    \
  97.     (p) = (type *) emalloc_rel(sizeof(type))
  98.  
  99. #define ZEND_FAST_FREE_REL(p, fc_type)    \
  100.     efree_rel(p)
  101.  
  102. #endif /* ZEND_ENABLE_FAST_CACHE */
  103.  
  104.  
  105.  
  106.  
  107. /* fast cache for zval's */
  108. #define ALLOC_ZVAL(z)    \
  109.     ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST)
  110.  
  111. #define FREE_ZVAL(z)    \
  112.     ZEND_FAST_FREE(z, ZVAL_CACHE_LIST)
  113.  
  114. #define ALLOC_ZVAL_REL(z)    \
  115.     ZEND_FAST_ALLOC_REL(z, zval, ZVAL_CACHE_LIST)
  116.  
  117. #define FREE_ZVAL_REL(z)    \
  118.     ZEND_FAST_FREE_REL(z, ZVAL_CACHE_LIST)
  119.  
  120. /* fast cache for HashTables */
  121. #define ALLOC_HASHTABLE(ht)    \
  122.     ZEND_FAST_ALLOC(ht, HashTable, HASHTABLE_CACHE_LIST)
  123.  
  124. #define FREE_HASHTABLE(ht)    \
  125.     ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST)
  126.  
  127. #define ALLOC_HASHTABLE_REL(ht)    \
  128.     ZEND_FAST_ALLOC_REL(ht, HashTable, HASHTABLE_CACHE_LIST)
  129.  
  130. #define FREE_HASHTABLE_REL(ht)    \
  131.     ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)
  132.  
  133. #endif /* ZEND_FAST_CACHE_H */
  134.  
  135. /*
  136.  * Local variables:
  137.  * tab-width: 4
  138.  * c-basic-offset: 4
  139.  * End:
  140.  */
  141.